#include <stdio.h>
#include <stdlib.h>
typedef enum { false, true } boolean;
#define MAGIC_ASCII 0x177 
boolean isBlank(char c);
/* prient input, one word per line */
int main(int argc, char** argv)
   {
	int scale =0;
	if (argc == 2)
	  { 
	    scale = atoi(argv[1]);
	    //    printf("scale: %d \n",scale);
	  }
	int letter[MAGIC_ASCII+1];
	int letterCount[MAGIC_ASCII+1];
	char c = (char)1;
	for (int i = 0; i <= MAGIC_ASCII ; i++)
	  letter[i]=i;
	for (int i = 0; i <= MAGIC_ASCII ; i++)
	  letterCount[i]=0;
     while ((c = getchar()) != EOF)
	  {
	    for(int i=0; i<=MAGIC_ASCII;i++)
		 // bug : doesn't keep track of endlines
		 if ((letter[i]==c) && (letter[i]!='\n'))
		   letterCount[i]++;
       }
	//	for (int i=0; i<=MAGIC_ASCII; i++)
	//{
	//  if (letterCount[i] >0)
	// printf("letter count: letter %c count %d \n",letter[i],letterCount[i]);
	// }

	// get count of columns
	int columns =0;
	for (int i=0; i<=MAGIC_ASCII; i++)
       {
	    if (letterCount[i]>0)
		 {
		   columns++;
		 }
	  }
	printf("columns: %d \n",columns);

	char smallerArray[columns];
	int smallerArrayCount[columns];
	for (int i=0; i < columns; i++)
	  {
	    smallerArray[i]=0;
	    smallerArrayCount[i]=0;
	  }
	int current_col=0;
    	for (int i=0; i<=MAGIC_ASCII; i++)
       {
	    printf ("letter: %c \n", letter[i]);
	    if (letterCount[i]>0)
		 {
		   printf("counted! \n");
   		   printf("i: %d lettercount: %d  current_col %d \n", i, letterCount[i],current_col);

		   smallerArrayCount[current_col]=letterCount[i];
		   smallerArray[current_col]=letter[i];
		   current_col++;
		 }
	  }
	for (int i=0; i<columns; i++)
	  {
		 printf("small letter count: letter %c count %d \n",smallerArray[i],smallerArrayCount[i]);
	  }
	
	// get max height
	int height =0;
	for (int i=0; i<=MAGIC_ASCII; i++)
       if (letterCount[i]>height) height=letterCount[i];
	printf("height: %d",height);


	for (int current_height=height; current_height>0; )
	  {
	    for (int i=0; i< columns; i++)
		 {
		   if (smallerArrayCount[i]>=current_height) putchar('#');
		   else putchar(' ');
		 }
	    putchar('\n');
    	    if(scale<=0)
		 current_height--;
	    else
		 current_height-=scale;
	  }
	for (int i =0; i < columns;i++)
	  {
	    if (smallerArray[i]==EOF)
		 { putchar(' '); }
	    if (isBlank(smallerArray[i]))
 		 { putchar(' '); }
	    else putchar(smallerArray[i]);
	  }
	putchar('\n'); //trailing endline
   return 0;  
  }

boolean isBlank(char c)
{
  if (c==' ')
    return true;
  if (c=='\n')
    return true;
  if (c=='\t')
    return true;
  return false;
} 
